package JavaSE.StreamLearning.ObjectStream.StaitcProblem;


import java.io.*;

public class Test {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //Student student = new Student(9527, "张三", new Teacher("李四", "语文"));
        //System.out.println(student.toString());
        //ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("src\\JavaSE.StreamLearning.ObjectStream\\StaitcProblem\\a.dat"));
        //oos.writeObject(student);
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src\\JavaSE.StreamLearning.ObjectStream\\StaitcProblem\\a.dat"));
        Object Student = ois.readObject();
        System.out.println("读取对象文件的内容：");
        System.out.println(Student.toString());
    }
}
//Serialization
class Student implements Serializable {
    static final long serialVersionUID = 3L;
    private static int id;
    private static String name = "wno";
    private Teacher teacher;
    String hobby;

    Student(int id, String name, Teacher teacher) {
        this.id = id;
        this.name = name;
        this.teacher = teacher;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", teacher=" + teacher +
                '}';
    }
}

class Teacher implements Serializable {
    static final long serialVersionUID = 4L;
    private String name;
    private transient String course = "数学";

    Teacher(String name, String course) {
        this.name = name;
        this.course = course;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", course='" + course + '\'' +
                '}';
    }
}